package cn.itsource.pethome.system.dictionary.service.imp;

import cn.itsource.pethome.base.service.impl.BaseServiceImpl;
import cn.itsource.pethome.system.dictionary.domain.DictionaryDetail;
import cn.itsource.pethome.system.dictionary.mapper.DictionaryDetailMapper;
import cn.itsource.pethome.system.dictionary.service.IDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author:R
 * @Date:2023/1/5 19:39
 * Description
 */
@Service
public class DictionaryDetailServiceImpl extends BaseServiceImpl<DictionaryDetail> implements IDictionaryDetailService {
    @Autowired
    private DictionaryDetailMapper detailMapper;
    @Transactional
    @Override
    public void add(DictionaryDetail dictionaryDetail) {
        if (detailMapper.findDictionary(dictionaryDetail) == 0){
            detailMapper.add(dictionaryDetail);
        }else {
            throw new RuntimeException("当前明细名称已重复"+dictionaryDetail.getName());
        }
    }

    @Transactional
    @Override
    public void update(DictionaryDetail dictionaryDetail) {
        if (detailMapper.findDictionary(dictionaryDetail) == 0){
            detailMapper.update(dictionaryDetail);
        }else {
            throw new RuntimeException("当前明细名称已重复【"+dictionaryDetail.getName()+"】");
        }
    }
}
